///*
// * Copyright 2016-2019 yoara
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// *     http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//package yhao.infra.feature.payment.demo;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import yhao.infra.common.cache.YhaoCache;
//import yhao.infra.common.cache.cachekey.CacheKeyType;
//
//import java.util.Map;
//
///**
// * Created by yoara on 2018/6/8.
// */
//public class PayCallBackHelper {
//    @Autowired
//    private YhaoCache redisCache;
//
//    public void cacheApplyPay(ApplyPayType applyPayType, String key, long empireTimeLong) {
//        redisCache.putHash(PaymentCacheKey.PAYMENT_CACHED_DATA, applyPayType.typeKey, key, empireTimeLong);
//    }
//
//    public void clearApplyPay(ApplyPayType applyPayType, String key) {
//        redisCache.removeHash(PaymentCacheKey.PAYMENT_CACHED_DATA, applyPayType.typeKey, key);
//    }
//
//    public void checkApplyPay(PayCallBackAction action,ApplyPayType applyPayType) {
//        Map<String, Object> hasCacheMap = redisCache.getHashAll(
//                PaymentCacheKey.PAYMENT_CACHED_DATA, applyPayType.typeKey);
//
//        if (hasCacheMap != null && !hasCacheMap.isEmpty()) {
//            for (Object obj : hasCacheMap.keySet()) {
//                String orderKey = (String) obj;
//                action.doAction(orderKey);
//                long empireTime = (long) hasCacheMap.get(obj);
//                if (System.currentTimeMillis() > empireTime) {//清除缓存
//                    clearApplyPay(applyPayType, orderKey);
//                }
//            }
//        }
//    }
//
//    public interface PayCallBackAction {
//        void doAction(String key);
//    }
//
//    public enum ApplyPayType {
//        ORDER("apply2payorders"),
//        LONG_ORDER_BILL("apply2paylongorderbills"),
//        LONG_ORDER_EXTRA_BILL("apply2paylongorderextrabills"),
//        LONG_ORDER_BOOKING("apply2paylongorderbooking"),
//        ;
//
//        private String typeKey;
//
//        ApplyPayType(String typeKey) {
//            this.typeKey = typeKey;
//        }
//    }
//
//    public enum PaymentCacheKey implements CacheKeyType {
//        PAYMENT_CACHED_DATA("COMPONENT_PAYMENT")
//        ;
//        private String baseType;
//
//        PaymentCacheKey(String baseType) {
//            this.baseType = baseType;
//        }
//
//        @Override
//        public String getCacheKey() {
//            return name();
//        }
//
//        @Override
//        public String getBaseType() {
//            return baseType;
//        }
//
//    }
//}
